package com.example.whm;



import java.util.List;

import org.holoeverywhere.LayoutInflater;
import org.holoeverywhere.app.Fragment;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.ViewGroup;

import com.androidquery.AQuery;
import com.example.whm.model.Address;
import com.example.whm.model.Box;

public class FourFragment extends Fragment {

	private AQuery aq; 
	private AQuery aq2;
	
	private String topic;
	Address add;
	List<Box> boxs;
	int num=0;
	int price=0;
	int tag;
	  FourFragmentOrder onef;
      FourFragmentPreorder twof;
      FourFragmentSubscribe threef;
      FragmentManager fm;
	
    @Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
    	View view = inflater.inflate(R.layout.four_layout, container, false); 
    	aq=new AQuery(getActivity());
    	aq2=new AQuery(getActivity(), view);
        fm=getChildFragmentManager();
        
    	return view;
	}






	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		
		showf(0);
	}

	
	public void showf(int pos){
		  if (fm==null) {
			  fm=getChildFragmentManager();
		}
		  FragmentTransaction transaction = fm.beginTransaction();   
	        
			switch (pos) {  
	        case 0:
	        	hideFragments(transaction); 
	        	System.out.println("===================== showf 0");
	        	if (onef == null) {  
	        		 onef = new  FourFragmentOrder();  
	                transaction.add(R.id.four_layout, onef);  
	            } else {            
	                transaction.show(onef);  
	            } 
	        	break;
	        case 1:
	        	hideFragments(transaction); 
	        	if (twof == null) {  
	        		twof = new  FourFragmentPreorder();  
	                transaction.add(R.id.four_layout, twof);  
	            } else {  
	                transaction.show(twof);  
	            } 
	        	break;
	        case 2:
	        	hideFragments(transaction); 
	        	if (threef == null) {  
	        		threef = new  FourFragmentSubscribe();  
	                transaction.add(R.id.four_layout, threef);  
	            } else {  
	                transaction.show(threef);  
	            } 
	        	break;
	        default:  
	            break; 
			}     
			transaction.commit();
	}
	
	private void hideFragments(FragmentTransaction transaction) {  
      
		if (onef != null) {  
            transaction.hide(onef);  
        }  
        if (twof != null) {  
            transaction.hide(twof);  
        }  
        if (threef != null) {  
            transaction.hide(threef);  
        }  
        
    }








    
 
}
